<?php if (!defined("_ECRIRE_INC_VERSION")) return;

/**
 *  Dymanic Tag wich outputs product price according to product's or given currency
 *  Format: #ECATALOGUE_PRODUCT_PRICE{<id_article>[, <currency_code>][, <type>]}
 *      If you want to output price in product's currency, dont specify currency_code
 *      If you want to output not standart price, specify it's type (<type>), i.e. type="priceold"
 */

function balise_ECATALOGUE_PRODUCT_PRICE($p) {	
	return calculer_balise_dynamique($p,'ECATALOGUE_PRODUCT_PRICE', array());
}

function balise_ECATALOGUE_PRODUCT_PRICE_stat($args, $filtres) {    
	return $args;
}

function balise_ECATALOGUE_PRODUCT_PRICE_dyn($id_article, $currency_code = false, $type = 'price', $qnty=1) {
	include_spip('functions/pdk_common.php');
    $product_mdl = pdk_load_class('ProductModel','classes/');
	$currency_mdl = pdk_load_class('CurrencyModel','classes/');
    
	if ($currency_code == 'CURRENT')
		$currency_code = $currency_mdl->GetCurrentCurrencyCode();
	
    // If some exceptions are thrown - return empty value 
    try {
        $price = $product_mdl->GetProductPrice($id_article, $currency_code, $type);
    } catch (Exception $e) {
        $price = '';
    } 
    if ($price==0) $price = '';
	$price = $price*$qnty;
    return array('balise/ecatalogue_product_price', 0, 
		array('price' => $price            
    ));
}

?>